<template>
  <div class="prompt-container" v-if="isVisible">
    <div class="prompt-box">
      <div class="prompt-title">
        <div style="display: flex; align-items: center">
          <!-- <svg-icon
            icon-class="cuowu_icon"
            style="width: 16px; height: 16px; margin-right: 8px"
          /> -->
          <div v-if="typeMessage == 'error'">错误</div>
          <div v-if="typeMessage == 'success' || typeMessage == ''">成功</div>
          <div v-if="typeMessage == 'warning'">警告</div>
          <!-- <div v-if="typeMessage == 'info'">正常</div> -->
        </div>
        <el-icon color="#fff" @click="confirmInput" size="16"><Close /></el-icon>
      </div>
      <div class="prompt-content">
        <div class="prompt-content-box" v-if="typeMessage == 'error'">
          <svg-icon
            icon-class="cuowumessage_icon"
            style="flex:0 0 32px; height: 32px; margin-right: 20px;color:#EB4015"
          />
          <div class="prompt-content-box-content">
              {{ contentMessage }}
          </div>
        </div>
        <div class="prompt-content-box" v-if="typeMessage == 'success'">
          <svg-icon
            icon-class="chenggong_iconmessage"
            style="flex:0 0 32px; height: 32px; margin-right: 20px;color:#67c23a"
          />
          <div class="prompt-content-box-content">
              {{ contentMessage }}
          </div>
        </div>
        <div class="prompt-content-box" v-if="typeMessage == 'warning'">
          <svg-icon
            icon-class="jinggao_iconmessage"
            style="flex:0 0 32px; height: 32px; margin-right: 20px;color:#e6a23c"
          />
          <div class="prompt-content-box-content">
              {{ contentMessage }}
          </div>
        </div>
        <div class="prompt-content-box" v-if="typeMessage == ''">
          <svg-icon
            icon-class="chenggong_iconmessage"
            style="flex:0 0 32px; height: 32px; margin-right: 20px;color:#67c23a"
          />
          <div class="prompt-content-box-content">
              {{ contentMessage }}
          </div>
        </div>
        <!-- <div class="prompt-content-box" v-if="typeMessage == 'info' || typeMessage == ''" style="background: #e9e9eb;border: 1px solid #e9e9eb;">
          <svg-icon
            icon-class="cuowu_icon"
            style="flex:0 0 16px; height: 16px; margin-right: 8px;color:#909399"
          />
          <div class="prompt-content-box-content">
              {{ contentMessage }}
          </div>
        </div> -->
      </div>
      <div class="prompt-footer">
        <el-button type="primary" style="width:80px;height:32px" @click="confirmInput">确定</el-button>
        <!-- <el-button @click="cancelPrompt">取消</el-button> -->
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
const { proxy } = getCurrentInstance();
const isVisible = ref(false);
const title = ref('')
const typeMessage = ref('info')
const contentMessage = ref('')
let resolvePromise = null;
let rejectPromise = null;
let promise = new Promise((res, rej) => {
  resolvePromise = res;
  rejectPromise = rej;
});
const showPrompt = (type,content) => {
  typeMessage.value = type
  contentMessage.value = content
  isVisible.value = true;
  return promise;
};

// const cancelPrompt = () => {
//   isVisible.value = false;
//   resolvePromise(
//     JSON.stringify('取消')
//   );
// };

const confirmInput = () => {
  isVisible.value = false;
  resolvePromise(
    '确定'
  );
  if (resolvePromise) {
    resolvePromise = null;
    rejectPromise = null;
    promise = new Promise((res, rej) => {
      resolvePromise = res;
      rejectPromise = rej;
    });
  }
};


defineExpose({
  isVisible,
  showPrompt,
  // cancelPrompt,
  confirmInput,
});
</script>

<style lang="scss" scoped>
.prompt-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  border-radius: 4px 4px 4px 4px;
  display: flex;
  
  justify-content: center;
  align-items: center;
  z-index: 10000;
}

.prompt-box {
  background-color: #fff;
  width: 612px;
  border-radius: 2px;
  box-shadow: 0px 12px 32px 4px rgba(0, 0, 0, 0.04),
    0px 8px 20px rgba(0, 0, 0, 0.08);
  .prompt-title {
    color: #303133;
    width: 100%;
    height: 40px;
    padding: 0 16px;
    box-sizing: border-box;
    background: #697786;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 16px;
    color: #ffffff;
  }
  .prompt-content {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 0 16px 0;
    box-sizing: border-box;
    .prompt-content-box{
        width: 564px;
        min-height: 48px;
        border-radius: 4px 4px 4px 4px;
        display: flex;
        align-items: center;
        // padding: 0 6px 0 20px;
        box-sizing: border-box;
        .prompt-content-box-content{
            flex: 1;
            font-size: var(--size);
            color: #333333;
            // overflow: hidden;
            // text-overflow: ellipsis;
            // white-space: nowrap;
            // cursor: pointer;
        }
    }
  }
  .detail-info{
    padding: 0 24px 24px 24px;
    box-sizing: border-box;
    .detail-info-top{
        display: flex;
        align-items: flex-end;
        color: #333333;
        .detail-info-top-title{
            font-size: var(--size);
        }
    }
    .detail-info-content{
        font-size: var(--size);
        color: #999999;
        width: 100%;
        margin-top: 16px;
        max-height: 188px;
        overflow-y: auto;
    }
  }
}

button {
  padding: 8px 15px;
  margin: 5px;
  cursor: pointer;
}
.prompt-footer {
  width: 100%;
  // height: 68px;
  display: flex;
  align-items: center;
  justify-content: center;
  // border-top: 1px solid #E0E0E0;
  // padding-right: 16px;
  box-sizing: border-box;
  margin-bottom: 12px;
}
</style>
<style>
.el-popper{
    z-index: 100000 !important;
}
</style>